#!/bin/sh

# This script is a modified version of what is available on 
# slackware-12.1/source/xap/mozilla-firefox/
# 
# Modified by Vincent Batts, vbatts@gmail.com 

PRGNAM="flock"
VERSION=2.5
ARCH=${ARCH:-i686}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}

CWD=$(pwd)
TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

set -e

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT

mkdir -p $PKG/usr/lib
cd $PKG/usr/lib
  tar xvf $CWD/${PRGNAM}-$VERSION.en-US.linux-i686.tar.bz2
  chown -R root:root .
  mv ${PRGNAM} $PRGNAM-$VERSION
  ln -sf $PRGNAM-$VERSION ${PRGNAM}
  cd $PRGNAM-$VERSION
  zcat $CWD/$PRGNAM-simple.diff.gz | patch -p0 
  zcat $CWD/$PRGNAM-thunderbird.diff.gz | patch -p0
  zcat $CWD/$PRGNAM.moz_plugin_path.diff.gz | patch -p0
  rm -f defaults/pref/$PRGNAM.js.orig
  mv ${PRGNAM}-browser ${PRGNAM}
cd -

mkdir -p $PKG/usr/bin
( cd $PKG/usr/bin
  ln -sf /usr/lib/$PRGNAM-$VERSION/${PRGNAM} $PRGNAM-bin
)

mkdir -p $PKG/usr/lib/mozilla/plugins

mkdir -p $PKG/usr/share/applications
cat $CWD/$PRGNAM.desktop > $PKG/usr/share/applications/$PRGNAM.desktop

mkdir -p $PKG/usr/share/pixmaps
cat $CWD/${PRGNAM}.png > $PKG/usr/share/pixmaps/$PRGNAM.png

# These files/directories are usually created if Flock is run as root, which on many
# systems might (and possibly should) be never.  Therefore, if we don't see them we'll
# put stubs in place to prevent startup errors.
cd $PKG/usr/lib/$PRGNAM-$VERSION
  if [ -d extensions/talkback\@mozilla.org ]; then
    if [ ! -r extensions/talkback\@mozilla.org/chrome.manifest ]; then
      echo > extensions/talkback\@mozilla.org/chrome.manifest
    fi
  fi
  if [ ! -d updates ]; then
    mkdir -p updates/0
  fi
cd -

mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cp $PKG/usr/lib/$PRGNAM-$VERSION/README.txt $PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

mkdir $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat $CWD/doinst.sh > $PKG/install/doinst.sh

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.tgz

